#include "key.h"    

static const char* TAG = "app_key";

void app_key_task(void *arg)
{
    key_event_t evt;
    //按键初始化
    keys_init();

    while(1)
    {
        //等待按键事件
        if(key_get_event(&evt, portMAX_DELAY))
        {
            //处理按键事件
            if(evt.act == KEY_ACT_CLICK){
                if(evt.id == KEY_ID_PREV){
                    ESP_LOGI(TAG,"KEY PREV CLICKED");
                }else if(evt.id == KEY_ID_NEXT){
                    ESP_LOGI(TAG,"KEY NEXT CLICKED");
                }else if(evt.id == KEY_ID_OK){
                    ESP_LOGI(TAG,"KEY OK CLICKED");
            }
            }
            else if(evt.act == KEY_ACT_PRESS){
                if(evt.id == KEY_ID_PREV){
                    ESP_LOGI(TAG,"KEY PREV PRESSED");
                }else if(evt.id == KEY_ID_NEXT){
                    ESP_LOGI(TAG,"KEY NEXT PRESSED");
                }else if(evt.id == KEY_ID_OK){
                    ESP_LOGI(TAG,"KEY OK PRESSED");
                }
            }
            else if(evt.act == KEY_ACT_RELEASE){
                if(evt.id == KEY_ID_PREV){
                    ESP_LOGI(TAG,"KEY PREV RELEASED");
                }else if(evt.id == KEY_ID_NEXT){
                    ESP_LOGI(TAG,"KEY NEXT RELEASED");
                }else if(evt.id == KEY_ID_OK){
                    ESP_LOGI(TAG,"KEY OK RELEASED");
                }       
            }
        }
    }   
    vTaskDelay(pdMS_TO_TICKS(50));
}
